package net.realsee.controller.wcs.device;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import net.realsee.common.annotation.Log;
import net.realsee.common.annotation.RepeatSubmit;
import net.realsee.common.enums.BusinessType;
import net.realsee.common.utils.poi.ExcelUtil;
import net.realsee.domain.wcs.device.WcsVehicleStatus;
import net.realsee.domain.wcs.device.bo.WcsVehicleStatusBo;
import net.realsee.domain.wcs.device.vo.WcsVehicleStatusVo;
import net.realsee.framework.core.controller.BaseController;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.domain.R;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.framework.core.validate.AddGroup;
import net.realsee.framework.core.validate.EditGroup;
import net.realsee.service.wcs.device.IWcsVehicleStatusService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 车辆状态信息
 *
 * @author realsee
 * @date 2023-08-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wcs/vehicleStatus")
public class WcsVehicleStatusController extends BaseController {

    private final IWcsVehicleStatusService iWcsVehicleStatusService;

    /**
     * 查询车辆状态信息列表
     */
    @SaCheckPermission("wcs:vehicleStatus:list")
    @GetMapping("/list")
    public TableDataInfo<WcsVehicleStatusVo> list(WcsVehicleStatusBo bo, PageQuery pageQuery) {
        return iWcsVehicleStatusService.selectVoPage(bo, pageQuery);
    }

    @GetMapping("/listNoPage")
    public R<List<WcsVehicleStatus>> listNoPage() {
        return R.ok(iWcsVehicleStatusService.queryListNoPage());
    }

    /**
     * 导出车辆状态信息列表
     */
    @SaCheckPermission("wcs:vehicleStatus:export")
    @Log(title = "车辆状态信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WcsVehicleStatusBo bo, HttpServletResponse response) {
        List<WcsVehicleStatusVo> list = iWcsVehicleStatusService.selectVoList(bo);
        ExcelUtil.exportExcel(list, "车辆状态信息", WcsVehicleStatusVo.class, response);
    }

    /**
     * 获取车辆状态信息详细信息
     *
     * @param status 主键
     */
    @SaCheckPermission("wcs:vehicleStatus:query")
    @GetMapping("/{status}")
    public R<WcsVehicleStatusVo> getInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable String status) {
        return R.ok(iWcsVehicleStatusService.selectVoById(status));
    }

    /**
     * 新增车辆状态信息
     */
    @SaCheckPermission("wcs:vehicleStatus:add")
    @Log(title = "车辆状态信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WcsVehicleStatusBo bo) {
        return toAjax(iWcsVehicleStatusService.insertByBo(bo));
    }

    /**
     * 修改车辆状态信息
     */
    @SaCheckPermission("wcs:vehicleStatus:edit")
    @Log(title = "车辆状态信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WcsVehicleStatusBo bo) {
        return toAjax(iWcsVehicleStatusService.updateByBo(bo));
    }

    /**
     * 删除车辆状态信息
     *
     * @param statuss 主键串
     */
    @SaCheckPermission("wcs:vehicleStatus:remove")
    @Log(title = "车辆状态信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{statuss}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] statuss) {
        return toAjax(iWcsVehicleStatusService.deleteWithValidByIds(Arrays.asList(statuss)));
    }
}
